Stata erroneously omits {res} when -display- is used in a loop, causing the displayed result to take the display style of the previous line. If there is no other previous style, it takes the {com} style of the loop itself.
When -display- is used in -foreach-, -forvalues-, or -while-, it should print:
But instead it prints:
This is not a new issue, and as of five years ago technical support even reported that they were "taking a look". I've re-reported the issue, but am also posting here for searchability. In addition, I clarify that the issue is not simply that "as error" persists. Other styles also persist, such as "as text", "as input", and even the "command" style of the loop itself.

When -display- is used in -foreach-, -forvalues-, or -while-, it should print:
Code:
{res} foo
Code:
foo
Code:
// Demonstrate issue with -forvalues-: forvalues i = 1/1 { display "implicit res <- bug" display as err "explicit err <- properly styled" display "implicit res <- bug" display as txt "explicit txt <- properly styled" display "implicit res <- bug" display as com "explicit com <- properly styled" display "implicit res <- bug" display as res "explicit res <- properly styled" display "implicit res <- technically bug, but properly styled anyway" }
Code:
. // Demonstrate issue with -forvalues-: . forvalues i = 1/1 {c -(} {txt} 2{com}. display "implicit res <- bug" {txt} 3{com}. display as err "explicit err <- properly styled" {txt} 4{com}. display "implicit res <- bug" {txt} 5{com}. display as txt "explicit txt <- properly styled" {txt} 6{com}. display "implicit res <- bug" {txt} 7{com}. display as com "explicit com <- properly styled" {txt} 8{com}. display "implicit res <- bug" {txt} 9{com}. display as res "explicit res <- properly styled" {txt} 10{com}. display "implicit res <- technically bug, but properly styled anyway" {txt} 11{com}. {c )-} implicit res <- bug {err}explicit err <- properly styled implicit res <- bug {txt}explicit txt <- properly styled implicit res <- bug {com}explicit com <- properly styled implicit res <- bug {res}explicit res <- properly styled implicit res <- technically bug, but properly styled anyway
Comment